import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import { resolve } from 'path'

// https://vitejs.dev/config/

export default defineConfig({
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  plugins: [
    vue(),
    legacy({
      targets: ['defaults', 'not IE 11']
    })],
  base: './',
  publicPath: process.env.NODE_ENV === 'production' ? '/dist/' : '/',

  build: {
    brotliSize: false,
    emptyOutDir: false,
    outDir: 'dist',
    assetsDir: 'static'
  },

  server: {
    host: 'localhost',
    port: 8086,
    open: false, // 自动打开,
    https: false, // 不启用https
    base: './', // 生产环境路径
    proxy: { // 没生效，不知道为什么
      '/v1': {
        target: 'http://172.31.139.88:8080/v1/',
        changeOrigin: true
        // rewrite: (path) => path.replace(/^\/api/, '')
        // pathRewrite: {
        //   '^': '/api'
        // }
      }
      // api: 'http://218.89.171.168:57947'
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "./src/assets/common/common.scss";'// 引用公共样式，使用vite搭建项目只安装sass即可，不需要安装node-sass,sass-loader
      }
    }
  }

})
